﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using System.Web.Http.Results;
using ZHDJ.AppInterface.Common;
using ZHDJ.AppInterface.Models;
using ZHDJ.Core;
using ZHDJ.Core.Util;
using ZHDJ.Data;
using ZHDJ.Data.BLL;
using ZHDJ.JoinParty.BLL;

namespace ZHDJ.AppInterface.Controllers
{
    public class CommentController : ApiController
    {
        #region 提交评论
        [HttpPost]
        public ReturnResult Save(dynamic obj)
        {
            ReturnResult result = new ReturnResult();
            PartyComment model = new PartyComment();
            string LoginID = Convert.ToString(obj.LoginID);
            model.ID = StringHelper.NewID;
            model.RelationID = Convert.ToString(obj.RelationID);
            model.Content = Convert.ToString(obj.Content);
            model.ImageID = Convert.ToString(obj.ImageID);
            model.ImageDesc = Convert.ToString(obj.ImageDesc);
            model.Module = Convert.ToString(obj.Module);
            model.DataCreateType = Convert.ToInt32(obj.DataCreateType);
            model.CreateTime = DateTime.Now;
            model.CreateBy = LoginID;
            if (InterfaceHelper.SaveComment(model) > 0)
            {
                result.code = "200";
                result.msg = "success";
            }
            else
            {
                result.code = "201";
                result.msg = "error";
            }
            return result;
        }
        #endregion

        #region 获取评论
        [HttpPost]
        public ReturnResult GetComment(dynamic obj)
        {
            DataTable dt = new DataTable();
            IList<PartyComment> list = new List<PartyComment>();
            int pageIndex = Convert.ToInt32(obj.pageIndex);
            int pageSize = Convert.ToInt32(obj.pageSize);
            string RelationID = Convert.ToString(obj.RelationID);//关联ID

            dt = InterfaceHelper.GetComment(pageIndex, pageSize, RelationID);
            if (dt.Rows.Count > 0)
                list = DataTableToListModel<PartyComment>.ConvertToModel(dt);

            return new ReturnResult()
            {
                code = "200",
                result = list,
                msg = dt.Rows.Count.ToString()
            };
        }
        #endregion
    }
}
